package net.lab1024.sa.admin.module.exam.controller;

import net.lab1024.sa.admin.module.exam.domain.form.QuestionAddForm;
import net.lab1024.sa.admin.module.exam.domain.form.QuestionQueryForm;
import net.lab1024.sa.admin.module.exam.domain.form.QuestionUpdateForm;
import net.lab1024.sa.admin.module.exam.domain.vo.QuestionVO;
import net.lab1024.sa.admin.module.exam.service.QuestionService;
import net.lab1024.sa.base.common.domain.ValidateList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import cn.dev33.satoken.annotation.SaCheckPermission;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 试题表 Controller
 *
 * @Author cfsjiazy
 * @Date 2025-10-20 16:36:35
 * @Copyright 1.0
 */

@RestController
@Tag(name = "试题表")
public class QuestionController {

    @Resource
    private QuestionService questionService;

    @Operation(summary = "分页查询 @author cfsjiazy")
    @PostMapping("/question/queryPage")
    @SaCheckPermission("question:query")
    public ResponseDTO<PageResult<QuestionVO>> queryPage(@RequestBody @Valid QuestionQueryForm queryForm) {
        return ResponseDTO.ok(questionService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author cfsjiazy")
    @PostMapping("/question/add")
    @SaCheckPermission("question:add")
    public ResponseDTO<String> add(@RequestBody @Valid QuestionAddForm addForm) {
        return questionService.add(addForm);
    }

    @Operation(summary = "更新 @author cfsjiazy")
    @PostMapping("/question/update")
    @SaCheckPermission("question:update")
    public ResponseDTO<String> update(@RequestBody @Valid QuestionUpdateForm updateForm) {
        return questionService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author cfsjiazy")
    @PostMapping("/question/batchDelete")
    @SaCheckPermission("question:delete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return questionService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author cfsjiazy")
    @GetMapping("/question/delete/{id}")
    @SaCheckPermission("question:delete")
    public ResponseDTO<String> batchDelete(@PathVariable Long id) {
        return questionService.delete(id);
    }
}
